package org.shopen.puremvc.view
{
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	import org.shopen.puremvc.ApplicationConstants;
	import org.shopen.puremvc.model.ManifestProxy;
	import org.shopen.puremvc.model.domain.OrganizationMeta;
	import org.shopen.puremvc.view.components.IntroWindow;

	public class IntroWindowMediator extends Mediator
	{
		public static const NAME : String = "IntroWindowMediator";
		
		public function IntroWindowMediator(viewComponent:Object=null)
		{
			super(IntroWindowMediator.NAME, viewComponent);
		}
		
		override public function getMediatorName():String
		{
			return IntroWindowMediator.NAME;
		}
		
		override public function onRegister():void
		{
			facade.registerMediator(new StageSelectorMediator(introWindow.stageSelector));
			facade.registerMediator(new TestingSelectorMediator(introWindow.testingSelector));
			sendNotification(ApplicationConstants.CONFIGURE_CONTENT);
		}
		
		protected function get introWindow() : IntroWindow
		{
			var result : IntroWindow = viewComponent as IntroWindow;
			return result;
		}
		
		override public function listNotificationInterests():Array
		{
			return [ManifestProxy.ORGANIZATION_META_AVAILABLE,
					ManifestProxy.MANIFEST_LOAD_FAILED];
		}
		
		override public function handleNotification(notification:INotification):void
		{
			var notificationName : String = notification.getName();
			switch (notificationName)
			{
				case ManifestProxy.ORGANIZATION_META_AVAILABLE:
					var orgMeta : OrganizationMeta = notification.getBody() as OrganizationMeta;
					introWindow.author = orgMeta.author;
					introWindow.organizationTitle = orgMeta.title;
					break;
				case ManifestProxy.MANIFEST_LOAD_FAILED:
					sendNotification(ApplicationConstants.GENERAL_ERROR, notification.getBody());
			}
		}
	}
}